Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "H+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
Date.prototype.DateAdd = function (number, interval) {
	switch(interval){  
            case   "y"   :   {  
                    date.setFullYear(this.getFullYear()+number);  
                    return   this;  
                    break;  
            }  
            case   "q"   :   {  
                    this.setMonth(this.getMonth()+number*3);  
                    return   this;  
                    break;  
            }  
            case   "M"   :   {  
                    this.setMonth(this.getMonth()+number);  
                    return   this;  
                    break;  
            }  
            case   "w"   :   {  
                    this.setDate(this.getDate()+number*7);  
                    return   this;  
                    break;  
            }  
            case   "d"   :   {  
                    this.setDate(this.getDate()+number);  
                    return   this;  
                    break;  
            }  
            case   "H"   :   {  
                    this.setHours(this.getHours()+number);  
                    return   this;  
                    break;  
            }  
            case   "m"   :   {  
                    this.setMinutes(this.getMinutes()+number);  
                    return   this;  
                    break;  
            }  
            case   "s "   :   {  
                    this.setSeconds(this.getSeconds()+number);  
                    return   this;  
                    break;  
            }  
            default   :   {  
                    this.setDate(this.getDate()+number);  
                    return   this;  
                    break;  
            }  
    } 
	return this;
}
function getParam(name, defaultValue) {
	     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	     var r = window.location.search.substr(1).match(reg);
	     if(r!=null)return  unescape(r[2]).replace(/^\s+|\s+$/gm,''); return (defaultValue==null?"":defaultValue);
	}

function getQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}

function echartsLine(xAxisData,series){
	option = {
	    tooltip : {trigger: 'axis'},
	    legend: {y:'bottom',data:[]},
	    xAxis : [{
	    	type : 'category',
	    	splitLine :{show:false},
	    	boundaryGap : false,
	    	data : xAxisData
	    }],
	    yAxis : [{type : 'value',splitLine :{show:false}}],
	    series : []
	};
	var index=0;
	$.each(series, function(i,v){
		if(v != null) {
			option.legend.data[index] = v.name;
			option.series[index] = {name:v.name,type:'line',data:v.data,markPoint : {
                data : [
	                    {type : 'max', name: '最大值'},
	                    {type : 'min', name: '最小值'}
	                ]
	            },
	            markLine : {
	                data : [
	                    {type : 'average', name: '平均值'}
	                ]
	            }};
			index++;
		}
	});
	return option;
}

function setMenu(name, isClear, isOpen){
	var menuKey = "menu";
	var menu = getCookie(menuKey);
	if(isOpen == null){
		isOpen = true;
	}
	if(isOpen){
		$(".side").removeClass("open");
		$(".side").click();
	}
	if(menu == null || menu == '' || isClear){
		menu = "[]";
	}
	var menuObj = eval("("+ menu +")");
	var menuObj2 = [];
	$.each(menuObj, function(i,v){
		if(v.pathname == location.pathname){
			return false;
		}
		menuObj2.push(v);
	});
	if(menuObj2.length == 0 || menuObj2.length <= menuObj.length){
		menuObj2.push({name:name,url:location.href,pathname:location.pathname});
	}
	setCookie(menuKey, JSON.stringify(menuObj2));
	$("#navList").loadData({navList:menuObj2});
	return menuObj2;
}


function updateMenuUrl(){
	var menuKey = "menu";
	var menu = getCookie(menuKey);
	if(menu == null || menu == '' || menu == '[]'){
		return null;
	}
	var menuObj = eval("("+ menu +")");
	menuObj[menuObj.length-1].url=location.href;
	setCookie(menuKey, JSON.stringify(menuObj));
}

function getFirstMenuUrl(){
	var menuKey = "menu";
	var menu = getCookie(menuKey);
	if(menu == null || menu == '' || menu == '[]'){
		return null;
	}
	var menuObj = eval("("+ menu +")");
	return menuObj[0].pathname;
}

function getPrevMenuUrl(){
	var menuKey = "menu";
	var menu = getCookie(menuKey);
	if(menu == null || menu == '' || menu == '[]'){
		return null;
	}
	var menuObj = eval("("+ menu +")");
	if(menuObj.length < 2){
		return null;
	}
	return menuObj[menuObj.length-2].url;
}
function hrefPrevUrl(){
	var url = getPrevMenuUrl();
	if(url != null){
		location.href=url;
	}
}


function setCookie(name,value){
	var Days = 30;
	var exp = new Date();
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape (value) +";path=/";
}	
function getCookie(c_name){
	if (document.cookie.length>0){
	  c_start=document.cookie.indexOf(c_name + "=")
	  if (c_start!=-1){ 
	    c_start=c_start + c_name.length+1 
	    c_end=document.cookie.indexOf(";",c_start)
	    if (c_end==-1) c_end=document.cookie.length
	    return unescape(document.cookie.substring(c_start,c_end))
	    } 
	  }
	return ""
}
function delCookie(name){
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=getCookie(name);
	if(cval!=null)
	document.cookie= name + "="+cval+";path=/";
}

$(function(){
	window.onscroll = function(){
        var t = document.documentElement.scrollTop || document.body.scrollTop;
        if(t>=50){
            $(".sidebar").css("top","0px")
            $(".top-nav").css("margin-top", "-50px");
        } else {
            $(".sidebar").css("top",(81-t)+"px")
            $(".top-nav").css("margin-top", "0px");
        }
    };
	if($(window).width() <= 1000){
    	$(".side").removeClass("open")
    };
	$(".side").click(function(){
	    if($(".side").hasClass("open")) {
	    	$(".side").removeClass("open")
	    	$(".sidebar").animate({left:'-160px'});
	        $(".cont").css("padding-left", "40px");
	    } else {
	        $(".side").addClass("open")
	        $(".sidebar").animate({left:"0px"});
	    	if($(window).width() > 1000){
	    		$(".cont").css("padding-left", "200px");
	    	}
	    }
	});
	
	 //筛选
    $(".table .caret-menu .btn").click(function(){
        $(this).parent().next().html($(this).html());
    });
    
    //排序
    $(".table .order").click(function(){
        if($(this).hasClass("desc")){
            $(this).removeClass("desc");
            $(this).addClass("asc");
            $(this).attr("data","desc");
        } else {
            $(this).removeClass("asc");
            $(this).addClass("desc");
            $(this).attr("data","asc");
        }
    });
  
});

function qiniuVideoImg(videoImg){
	if(videoImg != null) {
		var img = videoImg.split("_wh");
		if(img.length == 2) {
			var whStr = img[1].split(".");
			var whs = whStr[0].split("x");
			return videoImg+'?vframe/jpg/offset/2/w/'+whs[0]+'/h/'+whs[1];
		}
	}
	return videoImg+'?vframe/jpg/offset/2/w/960/h/720';
}

